#include "Car_run.h"
#include "Motor.h"
char Goto_flag = 0;
//*****************************************************FLAG_X_Run
void Car_Goto(char i)
{
    if (i == 1)
        Car_Flag_1_Run(), Goto_flag = 1;
    if (i == 2)
        Car_Flag_2_Run(), Goto_flag = 2;
        if (i == 3)
        Car_Flag_3_Run(), Goto_flag = 3;
         if (i == 4)
        Car_Flag_4_Run(), Goto_flag = 4;
}

void Car_Back(char i)
{
    if (i == 1)
        Car_Flag_1_Back();
    if (i == 2)
        Car_Flag_2_Back();
        if (i == 3)
        Car_Flag_3_Back();
        if (i == 4)
        Car_Flag_4_Back();
}


//*****************************************************FLAG_1_Run
void Car_Flag_1_Run(void)
{
    Car_LineMove(800, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_LEFT);
    Car_LineMove(450, SPEED_MIN, SPEED_MAX);
    MOTO_setAutoTimes(3);
    HAL_TIM_Base_Start_IT(&MOTOR_TIM);
}

void Car_Flag_1_Back(void)
{
    Car_LineMove(-450, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_RIGHT);
    Car_LineMove(-595, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_FLIP); //180度掉头
    MOTO_setAutoTimes(5);
    HAL_TIM_Base_Start_IT(&MOTOR_TIM);
}
//*****************************************************FLAG_2_Run
void Car_Flag_2_Run(void)
{
    Car_LineMove(800, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_RIGHT);
    Car_LineMove(400, SPEED_MIN, SPEED_MAX);
    MOTO_setAutoTimes(3);
    HAL_TIM_Base_Start_IT(&MOTOR_TIM);
}
void Car_Flag_2_Back(void)
{
    Car_LineMove(-400, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_LEFT);
    Car_LineMove(-595, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_LEFT);                      //180度掉头
    Car_Rotate(CAR_LEFT);
    MOTO_setAutoTimes(5);
    HAL_TIM_Base_Start_IT(&MOTOR_TIM);
}

void Car_Flag_3_Run(void)
{

    Car_LineMove(1700, SPEED_MIN, SPEED_MAX+50);
    Car_Rotate(CAR_LEFT);
    Car_LineMove(450, SPEED_MIN, SPEED_MAX+50);
    MOTO_setAutoTimes(3);
    HAL_TIM_Base_Start_IT(&MOTOR_TIM);
}

void Car_Flag_3_Back(void)
{
    
     Car_LineMove(-450, SPEED_MIN, SPEED_MAX+50);
    Car_Rotate(CAR_RIGHT);
    Car_LineMove(-1500, SPEED_MIN, SPEED_MAX+50);
    Car_Rotate(CAR_FLIP); //180度掉头
    MOTO_setAutoTimes(5);
    HAL_TIM_Base_Start_IT(&MOTOR_TIM);
}

void Car_Flag_4_Run(void)
{

    Car_LineMove(1700, SPEED_MIN, SPEED_MAX+50);
    Car_Rotate(CAR_RIGHT);
    Car_LineMove(450, SPEED_MIN, SPEED_MAX+50);
    MOTO_setAutoTimes(3);
    HAL_TIM_Base_Start_IT(&MOTOR_TIM);
}

void Car_Flag_4_Back(void)
{

    Car_LineMove(-450, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_LEFT);
    Car_LineMove(-1600, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_FLIP); //180度掉头
    MOTO_setAutoTimes(5);
    HAL_TIM_Base_Start_IT(&MOTOR_TIM);
}

void Car_Flag_5_Back(void)
{
    Car_Rotate(CAR_LEFT); //180度掉头
    Car_Rotate(CAR_LEFT);
    Car_LineMove(450, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_LEFT);
    Car_LineMove(900, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_RIGHT);
    Car_LineMove(2550, SPEED_MIN, SPEED_MAX);
}
void Car_Flag_6_Back(void)
{
    Car_Rotate(CAR_LEFT); //180度掉头
    Car_Rotate(CAR_LEFT);
    Car_LineMove(450, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_LEFT);
    Car_LineMove(900, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_LEFT);
    Car_LineMove(2550, SPEED_MIN, SPEED_MAX);
}
void Car_Flag_7_Back(void)
{
    Car_Rotate(CAR_LEFT); //180度掉头
    Car_Rotate(CAR_LEFT);
    Car_LineMove(450, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_RIGHT);
    Car_LineMove(900, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_RIGHT);
    Car_LineMove(2550, SPEED_MIN, SPEED_MAX);
}
void Car_Flag_8_Back(void)
{
    Car_Rotate(CAR_LEFT); //180度掉头
    Car_Rotate(CAR_LEFT);
    Car_LineMove(450, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_RIGHT);
    Car_LineMove(900, SPEED_MIN, SPEED_MAX);
    Car_Rotate(CAR_LEFT);
    Car_LineMove(2550, SPEED_MIN, SPEED_MAX);
}